﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../../Scripts/easyUI145/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Comm/JScript.js" type="text/javascript"></script>
    <script src="../../../Scripts/CommonUnite.js" type="text/javascript"></script>
    <script src="../../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../CCFlowEnum.js" type="text/javascript"></script>
    <link href="../../../Scripts/layui/layui/css/modules/layer/default/layer.css" rel="stylesheet" />
    <script src="../../../Scripts/layui/layui/lay/modules/layer.js"></script>

    <script type="text/javascript">
        var nodeID = GetQueryString("NodeID");
        var frmID = GetQueryString("FrmID");
        $(function () {
            if (window.parent.location.href.indexOf("En.htm") != -1)
                $("#backLink").hide();

            $("#sln").html("正在加载表单方案,请稍后...");

            //获取节点属性
            var node = new Entity("BP.WF.Template.NodeSimple", nodeID);

            //节点对应关系.
            var frmNodes = new Entities("BP.WF.Template.FrmNodes");
            frmNodes.Retrieve("FK_Flow", node.FK_Flow, "FK_Frm", frmID);

            var html = "<table class='table'>";
            html += "<thead>";
            html += "<tr>";
            html += "<th>#</th>";
            html += "<th>节点ID</th>";
            html += "<th>名称</th>";
            //   html += "<th>表单ID</th>";
            html += "<th>控制方案</th>";
            html += "<th>签批组件</th>";
            html += "<th>组件状态</th>";
            html += "<th>签名类型</th>";
            html += "<th>元素权限</th>";
            html += "<th>详情</th>";
            html += "</tr>";
            html += "</thead>";


            //获得节点s.
            var nodes = new Entities("BP.WF.Template.FrmWorkChecks");
            nodes.Retrieve("FK_Flow", node.FK_Flow);

            for (var i = 0; i < nodes.length; i++) {

                var json = nodes[i];

                //找到节点与表单的对应关系.
                var frmNode = null;
                for (var idx = 0; idx < frmNodes.length; idx++) {
                    var en = frmNodes[idx];
                    if (parseInt(en.FK_Node) != parseInt(json.NodeID))
                        continue;

                    frmNode = en;
                    html += "<tr>";
                    html += "<td>" + (i + 1) + "</td>";
                    html += "<td>" + json.NodeID + "</td>";
                    html += "<td>" + json.Name + "</td>";
                    //     html += "<td><a href=\"javascript:EditFrm('" + frmNode.FK_Frm + "')\" >" + frmNode.FK_Frm + "</a></td>";

                    //控制方案
                    html += "<td><select id='DDL_FrmSln_" + json.NodeID + "' ></select></td>";

                    //签批组件.
                    html += "<td><select id='DDL_CheckField_" + json.NodeID + "' ></select></td>";

                    //审核组件.
                    html += "<td><select id='DDL_FWCSta_" + json.NodeID + "' ></select></td>";

                    //签批组件.
                    html += "<td><select id='DDL_SigantureEnabel_" + json.NodeID + "' ></select></td>";

                    // 元素权限.
                    html += "<td>";
                    html += "[<a href=\"javascript:Fields('" + json.NodeID + "','" + frmNode.FK_Frm + "')\" >字段</a>]"; //
                    html += "[<a href=\"javascript:Aths('" + json.NodeID + "','" + frmNode.FK_Frm + "')\" >附件</a>]"; //
                    html += "[<a href=\"javascript:Dtls('" + json.NodeID + "','" + frmNode.FK_Frm + "')\" >从表</a>]"; //
                    html += "</td>"; //

                    html += "<td><a href=\"javascript:EditFrmNode('" + frmNode.MyPK + "');\" >详情</a></td>";
                    html += "</tr>";
                }
                //if (frmNode == null) {
                //    html += "<td colspan=3></td>";
                //    html += "</tr>";
                //    continue;
                //}
            }
            html += "</table>";
            $("#sln").html(html);


            //求出枚举值，然后绑定上.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_AttrNode_FrmSln");
            var frmID1 = frmNode == null ? frmID : frmNode.FK_Frm;
            handler.AddPara("FrmID", frmID1);
            var data = handler.DoMethodReturnJSON("BatchEditSln_InitDDLData");

            var frmSln = data["FrmSln"];
            var fwcSta = data["FWCSta"];
            var cfs = data["CheckFields"];
            $.each(cfs, function (idx, item) {
                if (item.No == null || item.No == undefined)
                    item.No = "";
            });

            var SigantureEnabel = data["SigantureEnabel"];

            //绑定ddl.
            for (var i = 0; i < nodes.length; i++) {

                var json = nodes[i];

                //找到节点与表单的对应关系.
                var frmNode = null;
                for (var idx = 0; idx < frmNodes.length; idx++) {
                    var en = frmNodes[idx];
                    if (en.FK_Node != json.NodeID)
                        continue;
                    frmNode = en;
                    break;
                }

                if (frmNode == null) {
                    continue;
                }

                //绑定方案.
                GenerBindDDL("DDL_FrmSln_" + json.NodeID, frmSln, "IntKey", "Lab", frmNode.FrmSln);

                //绑定状态.
                GenerBindDDL("DDL_FWCSta_" + json.NodeID, fwcSta, "IntKey", "Lab", frmNode.IsEnableFWC);

                //绑定字段.
                GenerBindDDL("DDL_CheckField_" + json.NodeID, cfs, "No", "Name", frmNode.CheckField);

                $("#DDL_CheckField_" + json.NodeID + " option:first").remove();//有两个“请选择”，移除一个

                //签字类型.
                GenerBindDDL("DDL_SigantureEnabel_" + json.NodeID, SigantureEnabel, "IntKey", "Lab", json.SigantureEnabel);

            }
        });

        function Fields(nodeID, frmID) {
            var url = "../../Sln/Fields.htm?FK_MapData=" + frmID + "&FK_Node=" + nodeID + "&FK_Flow=" + GetQueryString("FK_Flow") + "&DoType=Field";
            WinOpen(url);
        }
        function Aths(nodeID, frmID) {
            var url = "../../Sln/Aths.htm?FK_MapData=" + frmID + "&FK_Node=" + nodeID + "&FK_Flow=" + GetQueryString("FK_Flow") + "&DoType=Field";
            WinOpen(url);
        }
        function Dtls(nodeID, frmID) {
            var url = "../../Sln/Dtls.htm?FK_MapData=" + frmID + "&FK_Node=" + nodeID + "&FK_Flow=" + GetQueryString("FK_Flow") + "&DoType=Field";
            WinOpen(url);
        }

        // 绑定表单信息.
        function EditFrm(frmID) {
            var url = '../../FoolFormDesigner/GoToFrmDesigner.htm?FK_MapData=' + frmID + "&FrmID=" + frmID;
            window.open(url);
        }

        function EditFrmNode(mypk) {

            var url = '../../../Comm/En.htm?EnName=BP.WF.Template.FrmNodeExt&MyPK=' + mypk;
            window.open(url);
            return;

            OpenEasyUiDialog(url, "eudlgframe", '编辑', 900, 500, "icon-edit", true, null, null, null, function () {
                Reload();
            });
        }


        function Save() {
            //获取节点属性
            var node = new Entity("BP.WF.Template.NodeSimple", nodeID);
            //获得节点s.
            var nodes = new Entities("BP.WF.Template.NodeSimples");
            nodes.Retrieve("FK_Flow", node.FK_Flow);

            //节点对应关系.
            var frmNodes = new Entities("BP.WF.Template.FrmNodes");
            frmNodes.Retrieve("FK_Flow", node.FK_Flow);
            layer.load();//正在loading
            for (var i = 0; i < nodes.length; i++) {

                var json = nodes[i];
                //找到节点与表单的对应关系.
                var frmNode = null;
                var IsEnableFWC = 0;
                for (var idx = 0; idx < frmNodes.length; idx++) {
                    var en = frmNodes[idx];
                    if (en.FK_Node != json.NodeID)
                        continue;
                    var frmNode = new Entity("BP.WF.Template.FrmNode", en);
                    frmNode.FrmSln = $("#DDL_FrmSln_" + json.NodeID).val();
                    frmNode.IsEnableFWC = $("#DDL_FWCSta_" + json.NodeID).val();
                    frmNode.CheckField = $("#DDL_CheckField_" + json.NodeID).val();
                    frmNode.Update();

                    //..ss..dd.sss.
                    //var nodeWorkCheck = new Entity("BP.WF.Template.FrmWorkCheck", json.NodeID);
                    // nodeWorkCheck.SigantureEnabel = $("#DDL_SigantureEnabel_" + json.NodeID).val();
                    //nodeWorkCheck.Update();


                    if (IsEnableFWC == 0)
                        IsEnableFWC = frmNode.IsEnableFWC;

                    break;
                }
                var nd = new Entity("BP.WF.Template.NodeWorkCheck", json.NodeID);
                nd.FWCSta = IsEnableFWC;
                nd.SigantureEnabel = $("#DDL_SigantureEnabel_" + json.NodeID).val();
                nd.Update();

            }
            layer.closeAll('loading');
            alert('保存成功.');
            Reload();
        }


        function Back() {

            history.back();
        }

    </script>
</head>
<body>
    <div class="container-full">
        <div class="attrnode-bar-header">
            <span class="pull-right">

                <button id="Btn_Save" name="Btn_Save" onclick="Save();" class="cc-btn-tab btn-save">保存</button>
                <button id="Btn_Delete" name="Btn_Delete" onclick="Back();" class="cc-btn-tab btn-save">返回</button>
            </span>
            <strong>批量编辑节点与表单对应关系</strong>
        </div>

        <div id="sln"></div>

    </div>

</body>
</html>
